package twitter;

import java.util.ArrayList;

public class TwittProcesado extends Dendrogram{
	
	String twitt;
	//ArrayList<String> palabrasImportantes = new ArrayList<String>();
	//Hashtable<String,Integer> valoresIDF = new Hashtable<String,Integer>();
	
	private ArrayList<String> palabrasImportantes;
	private double[] vectorIdf;
	private int numeroCluster;
	//private double distanciaAlCentroide;
	
	public TwittProcesado(String cadena){
		super();
		twitt = cadena;
		palabrasImportantes = new ArrayList<String>();
		numeroCluster = 0;
		//distanciaAlCentroide = Double.MAX_VALUE;
	}
	
	public TwittProcesado(String frase, ArrayList<String> palabras){
		super();
		twitt = frase;
		palabrasImportantes = palabras;
		numeroCluster = 0;
		//distanciaAlCentroide = Double.MAX_VALUE;
	}

	public double coseno(double[] t2) {
		double prodEscalar=0.0;
		for (int i = 0; i < t2.length; i++) {
			prodEscalar += t2[i]*vectorIdf[i]; 
		}
		//System.out.println("producto escalar:"+prodEscalar);
		double moduloMio = calculaModulo();
		//System.out.println("modulo mio:"+moduloMio);
		double moduloT2 = calculaModulo(t2);
		//System.out.println("modulo t2:"+moduloT2);
		double coseno = prodEscalar/(moduloMio*moduloT2);
		//System.out.println("Coseno:"+coseno);
		return coseno;
	}
	
	private double calculaModulo() {
		return calculaModulo(vectorIdf);
	}
	
	private double calculaModulo(double[] vector) {
		double modulo=0.0;
		for (int i = 0; i < vector.length; i++) {
			modulo+=vector[i]*vector[i];
		}
		//System.out.println("Modulo cuadrado "+modulo+"******************RAIZ"+Math.sqrt(modulo));
		return Math.sqrt(modulo);
	}

	public double[] getVectorIdf(){
		return vectorIdf;
	}
	
	/*public void meteridfs(String cadena, int idf){
		valoresIDF.put(cadena, idf);
	}*/

	public ArrayList<String> getPalabrasImportantes() {
		return palabrasImportantes;
	}

	public void meteridfs(String string, double idf) {
		int indice=0;
		for (int i=0; i<EspacioVectorial.VEC_ATRIB.length; i++){
			if (EspacioVectorial.VEC_ATRIB[i].equals(string))
				break;
			indice++;
		}
		if (indice<vectorIdf.length)
			vectorIdf[indice]=idf;
	}

	public void inicializaVector() {
		vectorIdf = new double[EspacioVectorial.DIMENSION];
		for (int i=0; i<vectorIdf.length; i++){
			vectorIdf[i]=0;
		}
	}

	public int getNumeroCluster() {
		return numeroCluster;
	}

	public void setNumeroCluster(int numeroCluster) {
		this.numeroCluster = numeroCluster;
	}

	

	public String getTweet() {
		return twitt;
	}

	public void aniadePalabraImportante(String palabra) {
		palabrasImportantes.add(palabra);
	}
	
	
}

